/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dahamschool.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author LPK
 */
public final class HandlingQueries {

    ConnectionMysql mycon = new ConnectionMysql();

    public ResultSet getStudents() {
        ResultSet rs = null;
        try {
            Statement s = mycon.getConnection().createStatement();
            rs = s.executeQuery("SELECT * FROM student");

        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }
        return rs;
    }

    public ResultSet getSelectedStudent(String id) {
        ResultSet rs = null;
        try {
            Statement s = mycon.getConnection().createStatement();
            rs = s.executeQuery("SELECT * FROM student where id='" + id + "'");

        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }
        return rs;
    }

    public ResultSet getSelectedStudentByname(String name) {
        ResultSet rs = null;
        try {
            Statement s = mycon.getConnection().createStatement();
            rs = s.executeQuery("SELECT * FROM student where name='" + name + "'");

        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }
        return rs;
    }

    public boolean insertStudent(String sql) {
        int check = 0;
        try {
            Statement s = mycon.getConnection().createStatement();
            check = s.executeUpdate(sql);
        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }

        if (check > 0) {
            return true;
        } else {
            return false;
        }
    }

     public boolean deleteStudent(String sql) {
        int check = 0;
        try {
            Statement s = mycon.getConnection().createStatement();
            check = s.executeUpdate(sql);
        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }

        if (check > 0) {
            return true;
        } else {
            return false;
        }
    }
    
    
    
    public ResultSet test_image() {
        ResultSet rs = null;
        try {
            Statement s = mycon.getConnection().createStatement();
            rs = s.executeQuery("SELECT * FROM student where id=1");


        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }
        return rs;
    }

    public ResultSet UserLoginCheck(String username, String password) {
        ResultSet rs = null;
        try {
            Statement s = mycon.getConnection().createStatement();
            rs = s.executeQuery("SELECT * FROM login WHERE username='" + username + "'and password='" + password + "'");


        } catch (SQLException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }
        return rs;
    }
}
